home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / examples / misc / wexmast / slots.pro < prev    next >
Text File  |  1997-07-08  |  6KB  |  234 lines

  1. ; $Id: slots.pro,v 1.7 1997/01/15 04:29:15 ali Exp $
  2. ;
  3. ; Copyright (c) 1993-1997, Research Systems, Inc.  All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5.  
  6. ; This is a demo slot machine game.
  7.  
  8. PRO slots_event, event
  9.  
  10. COMMON slotsblock, handle, win1, win2, win3, done, money, bank, message
  11. COMMON pictures, pics, blank, handlepic, handlepic2, numfiles
  12. COMMON scoring, winval
  13.  
  14. winval = intarr(3)
  15.  
  16. WIDGET_CONTROL, event.id, GET_UVALUE = eventval
  17.  
  18.  
  19. CASE eventval OF
  20.     "PULL"    : BEGIN
  21.           ; Do the slot machine thang.
  22.  
  23.           ; Pull the handle down.
  24.           WIDGET_CONTROL, handle, SET_VALUE = handlepic2
  25.  
  26.           ; "Spin" the slot machine wheels.
  27.           extraspin = FIX(RANDOMU(SEED)*8)
  28.           spin1 = 15
  29.           spin2 = 20 + extraspin
  30.           spin3 = 25 + 2*extraspin
  31.           
  32.           FOR i = 0, spin3 DO BEGIN
  33.             r = FIX(RANDOMU(SEED, 3)* numfiles)
  34.             IF i LT spin1 THEN BEGIN
  35.             WIDGET_CONTROL, win1, SET_VALUE = pics[*,*,r[0]]
  36.             winval[0] = r[0]
  37.             ENDIF
  38.  
  39.             IF i LT spin2 THEN BEGIN
  40.             WIDGET_CONTROL, win2, SET_VALUE = pics[*,*,r[1]]
  41.             winval[1] = r[1]
  42.             ENDIF
  43.  
  44.             WIDGET_CONTROL, win3, SET_VALUE = pics[*,*,r[2]]
  45.  
  46.           ENDFOR
  47.           winval[2] = r[2]
  48.  
  49.           ; Put the handle back up.
  50.           WIDGET_CONTROL, handle, SET_VALUE = handlepic
  51.           
  52.           ; Increment or decrement the player's bankroll:
  53.           score, money, msg
  54.           WIDGET_CONTROL, bank, SET_VALUE = '$ ' + STRING(money)
  55.           WIDGET_CONTROL, message, SET_VALUE = msg 
  56.             
  57.           ; Is the player out of money? If they are, BACK TO WORK!
  58.           IF (money EQ 0) THEN WIDGET_CONTROL, event.top, /DESTROY
  59.  
  60.           END ; PULL case.
  61.  
  62.     "DONE"    : WIDGET_CONTROL, event.top, /DESTROY
  63.     ELSE    : donothing = 0
  64. ENDCASE
  65. END
  66.  
  67. PRO score, money, message
  68. COMMON scoring, winval
  69.  
  70. ; This procedure returns the new amount for the bankroll and a
  71. ; corresponding message.
  72.  
  73. IF (((winval[0] EQ 8) AND (winval[1] EQ 8)) AND (winval[2] EQ 8)) THEN $
  74.     BEGIN
  75.     money = money + 1000000000
  76.     message = 'SUPER HAL JACKPOT !!!'
  77.     RETURN
  78.     ENDIF    
  79.  
  80. IF ((winval[0] EQ winval[1]) AND (winval[1] EQ winval[2])) THEN $
  81.     BEGIN
  82.     money = money + 10
  83.     message = 'JACKPOT !!!'
  84.     RETURN
  85.     ENDIF
  86.  
  87. IF winval[0] EQ winval[1] THEN $
  88.     BEGIN
  89.     money = money + 2
  90.     message = 'Two of a Kind!'
  91.     RETURN
  92.     ENDIF
  93.  
  94. IF winval[1] EQ winval[2] THEN $
  95.     BEGIN
  96.     money = money + 3
  97.     message = 'Two of a Kind!'
  98.     RETURN
  99.     ENDIF
  100.  
  101. money = money - 1
  102. message = 'Bummer, Dude!' 
  103.  
  104. IF (money EQ 0) THEN message = 'Back to Work, Dude!'
  105.  
  106. RETURN
  107. END
  108.  
  109.  
  110. PRO makepics
  111. ; This procedure reads the bitmaps of the slot machine handle and wheels.
  112.  
  113. COMMON pictures, pics, blank, handlepic, handlepic2, numfiles
  114.  
  115. ; DEFINE THE PICS HERE:
  116.  
  117. blank = bytarr(8, 64)
  118.  
  119. ; Read the normal handle:
  120. OPENR, 5, FILEPATH('handle.bm', SUBDIR=['examples', 'misc', 'wexmast'])
  121. b = ASSOC(5, BYTARR(4,100))
  122. handlepic = b[0]
  123. CLOSE, 5
  124.  
  125. ; Read the pulled handle:
  126. OPENR, 5, FILEPATH('handle2.bm', SUBDIR=['examples', 'misc', 'wexmast'])
  127. b = assoc(5, BYTARR(4,100))
  128. handlepic2 = b[0]
  129. CLOSE, 5
  130.  
  131. ; The array 'files' contains the filenames for the icons to use. 
  132. ; You can add more pictures to the slot machine 'wheels' by creating new
  133. ; 64 by 64 bitmaps with XBM_EDIT and appending the names of their
  134. ; files to the list of names already shown.
  135.  
  136. files=['apple.bm','pc.bm','cherry.bm','face.bm','idlidl.bm','seven.bm',$
  137.        'disk.bm','orange.bm','hal.bm']
  138.  
  139. ; Find out how many pictures there are:
  140. numfiles = N_ELEMENTS(files)
  141.  
  142. ; The array pics will hold the wheel bitmaps:
  143. pics = BYTARR(8,64,numfiles)
  144.  
  145. ; Read each file described in 'files' into an element of array PICS:
  146. FOR i = 0, numfiles-1 DO BEGIN 
  147. OPENR, 5, FILEPATH(files[i], SUBDIR=['examples', 'misc', 'wexmast'])
  148. b = ASSOC(5, BYTARR(8,64))
  149. pics[*,*,i] = b[0]
  150. CLOSE, 5
  151. ENDFOR
  152.  
  153. END    ; PRO makepics 
  154.  
  155.  
  156.  
  157.  
  158. PRO slots, GROUP = GROUP
  159. ; This procedure make the slot machine widgets.
  160.  
  161. COMMON slotsblock, handle, win1, win2, win3, done, money, bank, message
  162. COMMON pictures, pics, blank, handlepic, handlepic2, numfiles
  163.  
  164.  
  165. ; Only one copy of the slot machine can run at a time, so check for other
  166. ; copies:
  167.  
  168. IF(XREGISTERED("slots") NE 0) THEN RETURN
  169.  
  170. makepics
  171.  
  172. base = WIDGET_BASE(TITLE = 'One-Armed Bandit', /ROW)
  173. lcol = WIDGET_BASE(base, /COLUMN)
  174. mcol = WIDGET_BASE(base, /COLUMN)
  175. rcol = WIDGET_BASE(base, /COLUMN, XSIZE = 44)
  176.  
  177. windows = WIDGET_BASE(mcol, /ROW)        ;Make the windows for MOTIF.
  178.  
  179. ; Widgets for the left column (lcol):
  180. ; Make the Quit button:
  181. done = WIDGET_BUTTON(lcol, VALUE = "Quit Goofin' Off", UVALUE = 'DONE')
  182.  
  183. ; Make the bankroll display window with a label above it:
  184. bankcol = WIDGET_BASE(lcol, /COLUMN, /FRAME)
  185. banklabel = WIDGET_LABEL(bankcol, VALUE = 'Bankroll:')
  186. bank = WIDGET_TEXT(bankcol, /FRAME, UVALUE = 'BANK')
  187.  
  188.  
  189. ; Widgets for the middle column (mcol):
  190. ; The three 'wheel' windows are rendered as buttons that don't really do anything, 
  191. ; they just display the little bitmap pictures:
  192. win1 = WIDGET_BUTTON(windows, VALUE = blank, UVALUE = 'WIN1')
  193. win2 = WIDGET_BUTTON(windows, VALUE = blank, UVALUE = 'WIN2')
  194. win3 = WIDGET_BUTTON(windows, VALUE = blank, UVALUE = 'WIN3')
  195.  
  196. ; Make the message area below the wheels:
  197. message = WIDGET_TEXT(mcol, VALUE = 'Click on the Handle to Play', /FRAME)
  198.  
  199. ; Make a section of labels that describe the scoring, etc.:
  200. info = WIDGET_BASE(mcol, /FRAME, /COLUMN)
  201.  
  202. ; The following lines demonstrate the use of the new FONT keyword to the 
  203. ; widget routines.  Just enclose the name of a font available on the
  204. ; appropriate machine in quotes as shown below:
  205.  
  206. VERSION    = WIDGET_INFO(/VERSION)
  207. IF (STRPOS(VERSION.STYLE, 'Windows') NE -1) THEN font='*24' $
  208. ELSE IF (STRPOS(VERSION.STYLE, 'Motif') NE -1) THEN font='fixed' $
  209. ELSE font='v*36' 
  210.  
  211. line1 = WIDGET_LABEL(info, FONT=font, VALUE = 'Match 1st Two --- $2') 
  212. line2 = WIDGET_LABEL(info, FONT=font, VALUE = 'Match 2nd Two --- $3')
  213. line3 = WIDGET_LABEL(info, FONT=font, VALUE = '3 of a Kind    --- $20')
  214. line4 = WIDGET_LABEL(info, FONT=font, VALUE = 'Three Hals    --- $1,000,000')
  215.  
  216. line5 = WIDGET_LABEL(info, VALUE = 'For Entertainment Purposes Only', /FRAME)
  217. line6 = WIDGET_LABEL(info, VALUE = 'Please, No Wagering',/FRAME)
  218.  
  219. ; Widgets for the right column:
  220. handle = WIDGET_BUTTON(rcol, VALUE = handlepic, UVALUE = 'PULL')
  221.  
  222. ; Initailize the bankroll:
  223. money = 10
  224. WIDGET_CONTROL, bank, SET_VALUE = '$ '+ STRING(money)
  225.  
  226. ; Realize the widgets:
  227. WIDGET_CONTROL, base, /REALIZE
  228.  
  229. ; Hand off to the XMANAGER:
  230. XMANAGER, 'slots', base, GROUP_LEADER = GROUP, /NO_BLOCK
  231.  
  232. END
  233.  
  234.